
<div id="tables">
    <h3 class="section">Tables</h3>
    <div class="content">

    <?php if(isset ($errorsTables) && is_array($errorsTables) && count($errorsTables) > 0) { ?>
        <p>
            <?php echo implode('<br />', $errorsTables); ?>
        </p>
    <?php } ?>

    <form action="index.php?controller=tables" method="post">
    <table border="1" class="tables" width="100%">
        <thead>
            <tr>
                <td>Table</td>
                <td width="50">
                    <label>
                        <input type="checkbox" />
                        DB                        
                    </label>
                </td>
                <td width="70">
                    <label>
                        <input type="checkbox" />
                        Schema                        
                    </label>
                </td>
                <td width="50">
                    <label>
                        <input type="checkbox" />
                        Data                        
                    </label>
                </td>
            </tr>
        </thead>

        <?php if (!is_array($tables) OR count($tables) < 1) { ?>
            <tr>
                <td colspan="4">
                    <p>No tables in DB or in Files</p>
                </td>
            </tr>
        <?php } else { ?>
            <?php foreach ($tables as $table) { ?>
                <tr>
                    <td><?php echo $table; ?></td>

                    <?php $checkbox = (in_array($table, $tablesDB)) ? 'yes' : 'no'; ?>
                    <td class="install <?php echo $checkbox; ?>">
                        <input type="checkbox" name="installTable[<?php echo $table; ?>]" value="On" id="installTable<?php echo $table; ?>" />
                        <label for="installTable<?php echo $table; ?>" ><?php echo $checkbox; ?></label>
                    </td>

                    <?php $checkbox = (in_array($table, $tablesFiles)) ? 'yes' : 'no'; ?>
                    <td class="structure <?php echo $checkbox; ?>">
                        <input type="checkbox" name="structureTable[<?php echo $table; ?>]" value="On" id="structureTable<?php echo $table; ?>" />
                        <label for="structureTable<?php echo $table; ?>" ><?php echo $checkbox; ?></label>
                    </td>

                    <?php $checkbox = (in_array($table, $tablesDataFiles)) ? 'yes' : 'no'; ?>
                    <td class="data <?php echo $checkbox; ?>">
                        <input type="checkbox" name="dataTable[<?php echo $table; ?>]" value="On" id="dataTable<?php echo $table; ?>" />
                        <label for="dataTable<?php echo $table; ?>" ><?php echo $checkbox; ?></label>
                    </td>
                </tr>
            <?php } ?>
            <tfoot>
            <tr>
                <td>
                    With Selected do:
                </td>
                <td>
                    <input type="submit" name="submit" value="Install" />
                </td>
                <td>
                    <input type="submit" name="submit" value="Make" />
                </td>
                <td>
                    <input type="submit" name="submit" value="Make" />
                </td>
            </tr>
            </tfoot>
        <?php } ?>
    </table>
    <script type="text/javascript">
        var inputs = $$('table thead input[type="checkbox"]');
        inputs.invoke('observe', 'click', function (event) {
            var input = event.findElement('input');
            var index = inputs.indexOf(input);

            $$('table.tables tbody tr').each(function (row) {
                row.down('td', index + 1).down('input').checked = input.checked;
            });
        });
    </script>
    </form>
    </div>
</div>